package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {
    //注入jedispool
    @Autowired
    private JedisPool jedisPool;
    ///删除七牛云上的图片(新增套餐未添加成功图片)
    public void clearImg() {
        System.out.println("任务即将开始执行");
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        for (String pic : sdiff) {
            //删除redis集合临时set文件//删除七牛云上的图片
            QiniuUtils.deleteFileFromQiniu(pic);
            jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, pic);
            System.out.println(pic+"已经被清理");
        }
    }
}
